package xyz.archknight.app.loginput.dictionary.gen.ui

import xyz.archknight.app.loginput.dictionary.gen.bean.ActionProtocol
import xyz.archknight.app.loginput.dictionary.gen.service.EventBus
import xyz.archknight.app.loginput.dictionary.gen.ui.component.SVGButton
import java.awt.Insets
import javax.swing.JToolBar

/**
 * 主工具栏
 *
 * @author midnite
 * create at 2020-06-17 8:34 上午
 */
class MainToolBar : JToolBar() {
    private val newButton = SVGButton("file", tip = "新建主词库")
    private val openButton = SVGButton("folder", tip = "打开主词库")
    private val saveButton = SVGButton("disk", tip = "保存主词库")
    private val importButton = SVGButton("import", tip = "由落格输入法词库导入")
    private val exportButton = SVGButton("export", tip = "导出为落格输入法词库")
    private val mixButton = SVGButton("migrate", tip = "将缓存区内容混入主词库")

    init {
        createUI()
    }

    private fun createUI() {
        margin = Insets(4, 4, 4, 4)
        add(newButton)
        add(openButton)
        add(saveButton)
        addSeparator()
        add(importButton)
        add(exportButton)
        addSeparator()
        add(mixButton)

        newButton.addActionListener { EventBus.sendToolbarAction(ActionProtocol.ResetDatabase) }
        openButton.addActionListener { EventBus.sendToolbarAction(ActionProtocol.LoadDatabase) }
        saveButton.addActionListener { EventBus.sendToolbarAction(ActionProtocol.SaveDatabase) }
        importButton.addActionListener { EventBus.sendToolbarAction(ActionProtocol.OpenImport) }
        exportButton.addActionListener { EventBus.sendToolbarAction(ActionProtocol.OpenExport) }
        mixButton.addActionListener { EventBus.sendToolbarAction(ActionProtocol.MixCacheInDatabase) }
    }
}